/*
 * Copyright (c) 2024 Black Sesame Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _DAL_CYCLONE_PARTICIPANT_GUID_MAP_HPP_
#define _DAL_CYCLONE_PARTICIPANT_GUID_MAP_HPP_

#include <string>
#include <iostream>
#include <unordered_map>
#include "dal/guid.h"

struct DalGuidForMap
{
    uint8_t data[GUID_SIZE];

    // DalGuidForMap() = delete;
    DalGuidForMap() {};
    DalGuidForMap(const dal_guid_t& guid)
    {
        // 复制 guidprefix 和 entity_id 到数组中
        memcpy(data, guid.guidprefix.value, GUIDPREFIX_SIZE);
        memcpy(data + GUIDPREFIX_SIZE, guid.entity_id.value, ENTITYID_SIZE);
    }

    DalGuidForMap(const DalGuidForMap& other) {
        memcpy(data, other.data, sizeof(data));
    }

    DalGuidForMap& operator=(const DalGuidForMap& other) {
    if (this != &other) {
        memcpy(data, other.data, sizeof(data));
    }
    return *this;
}

    bool operator==(const DalGuidForMap& other) const
    {
        for (int i = 0; i < GUID_SIZE; ++i) {
            if (data[i] != other.data[i]) {
                return false;
            }
        }
        return true;
    }

    std::size_t operator()(const DalGuidForMap& key) const
    {
        std::size_t hash = 0;
        for (int i = 0; i < sizeof(data); ++i) {
            hash = hash * 31 + data[i];
        }
        return hash;
    }
};

void ParticipantGuidMapInsert(const DalGuidForMap& guid, const std::string& name);
bool ParticipantGuidMapFind(const DalGuidForMap& guid, std::string& name);
void ParticipantGuidMapErase(const DalGuidForMap& guid);

void showGuid(const DalGuidForMap& guid);

#endif  // _DAL_CYCLONE_PARTICIPANT_GUID_MAP_HPP_